<span class='l l-1 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>module</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>Main</s> <s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>where</s>
</span><span class='l l-2 source haskell'>
</span><span class='l l-3 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>import</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>Paths_postgrest</s> (version)
</span><span class='l l-4 source haskell'>
</span><span class='l l-5 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>import</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>PostgREST</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>App</s>
</span><span class='l l-6 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>import</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>PostgREST</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Middleware</s>
</span><span class='l l-7 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>import</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>PostgREST</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Error</s>(errResponse)
</span><span class='l l-8 source haskell'>
</span><span class='l l-9 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>import</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>Control</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Monad</s> (unless)
</span><span class='l l-10 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>import</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>Control</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Monad</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>IO</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Class</s> (liftIO)
</span><span class='l l-11 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>import</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>Data</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>String</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Conversions</s> (cs)
</span><span class='l l-12 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>import</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>Network</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Wai</s> (strictRequestBody)
</span><span class='l l-13 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>import</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>Network</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Wai</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Middleware</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Cors</s> (cors)
</span><span class='l l-14 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>import</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>Network</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Wai</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Handler</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Warp</s> <s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>hiding</s> (<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Connection</s>)
</span><span class='l l-15 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>import</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>Network</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Wai</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Middleware</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Gzip</s> (gzip, def)
</span><span class='l l-16 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>import</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>Network</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Wai</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Middleware</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Static</s> (staticPolicy, only)
</span><span class='l l-17 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>import</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>Network</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Wai</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Middleware</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>RequestLogger</s> (logStdout)
</span><span class='l l-18 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>import</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>Data</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>List</s> (intercalate)
</span><span class='l l-19 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>import</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>Data</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Version</s> (versionBranch)
</span><span class='l l-20 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>import</s> qualified <s class='constant other haskell' data-entity-scope='constant.other.haskell'>Hasql</s> <s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>as</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>H</s>
</span><span class='l l-21 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>import</s> qualified <s class='constant other haskell' data-entity-scope='constant.other.haskell'>Hasql</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Postgres</s> <s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>as</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>P</s>
</span><span class='l l-22 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>import</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>Options</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Applicative</s> <s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>hiding</s> (columns)
</span><span class='l l-23 source haskell'>
</span><span class='l l-24 source haskell'><s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>import</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>PostgREST</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Config</s> (<s class='constant other haskell' data-entity-scope='constant.other.haskell'>AppConfig</s><s class='entity name function infix haskell' data-entity-scope='entity.name.function.infix.haskell'>(..)</s>, argParser, corsPolicy)
</span><span class='l l-25 source haskell'>
</span><span class='l l-26 source haskell'><s class='meta function type-declaration haskell' data-entity-scope='meta.function.type-declaration.haskell'><s class='entity name function haskell' data-entity-scope='entity.name.function.haskell'>main</s> <s class='punctuation separator double-colon haskell' data-entity-scope='punctuation.separator.double-colon.haskell'>::</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>IO</s> ()
</s></span><span class='l l-27 source haskell'>main <s class='punctuation separator equal-sign haskell' data-entity-scope='punctuation.separator.equal-sign.haskell'>=</s> <s class='keyword control haskell' data-entity-scope='keyword.control.haskell'>do</s>
</span><span class='l l-28 source haskell'>  <s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>let</s> opts <s class='punctuation separator equal-sign haskell' data-entity-scope='punctuation.separator.equal-sign.haskell'>=</s> info (helper &lt;*&gt; argParser) $
</span><span class='l l-29 source haskell'>                fullDesc
</span><span class='l l-30 source haskell'>                &lt;&gt; progDesc (
</span><span class='l l-31 source haskell'>                    <s class='string quoted double haskell' data-entity-scope='string.quoted.double.haskell'><s class='punctuation definition string begin haskell' data-entity-scope='punctuation.definition.string.begin.haskell'>&quot;</s>PostgREST <s class='punctuation definition string end haskell' data-entity-scope='punctuation.definition.string.end.haskell'>&quot;</s></s>
</span><span class='l l-32 source haskell'>                    &lt;&gt; prettyVersion
</span><span class='l l-33 source haskell'>                    &lt;&gt; <s class='string quoted double haskell' data-entity-scope='string.quoted.double.haskell'><s class='punctuation definition string begin haskell' data-entity-scope='punctuation.definition.string.begin.haskell'>&quot;</s> / create a REST API to an existing Postgres database<s class='punctuation definition string end haskell' data-entity-scope='punctuation.definition.string.end.haskell'>&quot;</s></s>
</span><span class='l l-34 source haskell'>                )
</span><span class='l l-35 source haskell'>      parserPrefs <s class='punctuation separator equal-sign haskell' data-entity-scope='punctuation.separator.equal-sign.haskell'>=</s> prefs showHelpOnError
</span><span class='l l-36 source haskell'>  conf &lt;- customExecParser parserPrefs opts
</span><span class='l l-37 source haskell'>  <s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>let</s> port <s class='punctuation separator equal-sign haskell' data-entity-scope='punctuation.separator.equal-sign.haskell'>=</s> configPort conf
</span><span class='l l-38 source haskell'>
</span><span class='l l-39 source haskell'>  unless (configSecure conf) $
</span><span class='l l-40 source haskell'>    <s class='entity name function builtin prelude haskell' data-entity-scope='entity.name.function.builtin.prelude.haskell'>putStrLn</s> <s class='string quoted double haskell' data-entity-scope='string.quoted.double.haskell'><s class='punctuation definition string begin haskell' data-entity-scope='punctuation.definition.string.begin.haskell'>&quot;</s>WARNING, running in insecure mode, auth will be in plaintext<s class='punctuation definition string end haskell' data-entity-scope='punctuation.definition.string.end.haskell'>&quot;</s></s>
</span><span class='l l-41 source haskell'>  unless (<s class='string quoted double haskell' data-entity-scope='string.quoted.double.haskell'><s class='punctuation definition string begin haskell' data-entity-scope='punctuation.definition.string.begin.haskell'>&quot;</s>secret<s class='punctuation definition string end haskell' data-entity-scope='punctuation.definition.string.end.haskell'>&quot;</s></s> /= configJwtSecret conf) $
</span><span class='l l-42 source haskell'>    <s class='entity name function builtin prelude haskell' data-entity-scope='entity.name.function.builtin.prelude.haskell'>putStrLn</s> <s class='string quoted double haskell' data-entity-scope='string.quoted.double.haskell'><s class='punctuation definition string begin haskell' data-entity-scope='punctuation.definition.string.begin.haskell'>&quot;</s>WARNING, running in insecure mode, JWT secret is the default value<s class='punctuation definition string end haskell' data-entity-scope='punctuation.definition.string.end.haskell'>&quot;</s></s>
</span><span class='l l-43 source haskell'>  <s class='constant other haskell' data-entity-scope='constant.other.haskell'>Prelude</s>.<s class='entity name function builtin prelude haskell' data-entity-scope='entity.name.function.builtin.prelude.haskell'>putStrLn</s> $ <s class='string quoted double haskell' data-entity-scope='string.quoted.double.haskell'><s class='punctuation definition string begin haskell' data-entity-scope='punctuation.definition.string.begin.haskell'>&quot;</s>Listening on port <s class='punctuation definition string end haskell' data-entity-scope='punctuation.definition.string.end.haskell'>&quot;</s></s> ++
</span><span class='l l-44 source haskell'>    (<s class='entity name function builtin prelude haskell' data-entity-scope='entity.name.function.builtin.prelude.haskell'>show</s> $ configPort conf :: <s class='constant other haskell' data-entity-scope='constant.other.haskell'>String</s>)
</span><span class='l l-45 source haskell'>
</span><span class='l l-46 source haskell'>  <s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>let</s> pgSettings <s class='punctuation separator equal-sign haskell' data-entity-scope='punctuation.separator.equal-sign.haskell'>=</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>P</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>ParamSettings</s> (cs $ configDbHost conf)
</span><span class='l l-47 source haskell'>                     (<s class='entity name function builtin prelude haskell' data-entity-scope='entity.name.function.builtin.prelude.haskell'>fromIntegral</s> $ configDbPort conf)
</span><span class='l l-48 source haskell'>                     (cs $ configDbUser conf)
</span><span class='l l-49 source haskell'>                     (cs $ configDbPass conf)
</span><span class='l l-50 source haskell'>                     (cs $ configDbName conf)
</span><span class='l l-51 source haskell'>      appSettings <s class='punctuation separator equal-sign haskell' data-entity-scope='punctuation.separator.equal-sign.haskell'>=</s> setPort port
</span><span class='l l-52 source haskell'>                  . setServerName (cs $ <s class='string quoted double haskell' data-entity-scope='string.quoted.double.haskell'><s class='punctuation definition string begin haskell' data-entity-scope='punctuation.definition.string.begin.haskell'>&quot;</s>postgrest/<s class='punctuation definition string end haskell' data-entity-scope='punctuation.definition.string.end.haskell'>&quot;</s></s> &lt;&gt; prettyVersion)
</span><span class='l l-53 source haskell'>                  $ defaultSettings
</span><span class='l l-54 source haskell'>      middle <s class='punctuation separator equal-sign haskell' data-entity-scope='punctuation.separator.equal-sign.haskell'>=</s> logStdout
</span><span class='l l-55 source haskell'>        . (<s class='keyword control haskell' data-entity-scope='keyword.control.haskell'>if</s> configSecure conf <s class='keyword control haskell' data-entity-scope='keyword.control.haskell'>then</s> redirectInsecure <s class='keyword control haskell' data-entity-scope='keyword.control.haskell'>else</s> <s class='entity name function builtin prelude haskell' data-entity-scope='entity.name.function.builtin.prelude.haskell'>id</s>)
</span><span class='l l-56 source haskell'>        . gzip def . cors corsPolicy
</span><span class='l l-57 source haskell'>        . staticPolicy (only [(<s class='string quoted double haskell' data-entity-scope='string.quoted.double.haskell'><s class='punctuation definition string begin haskell' data-entity-scope='punctuation.definition.string.begin.haskell'>&quot;</s>favicon.ico<s class='punctuation definition string end haskell' data-entity-scope='punctuation.definition.string.end.haskell'>&quot;</s></s>, <s class='string quoted double haskell' data-entity-scope='string.quoted.double.haskell'><s class='punctuation definition string begin haskell' data-entity-scope='punctuation.definition.string.begin.haskell'>&quot;</s>static/favicon.ico<s class='punctuation definition string end haskell' data-entity-scope='punctuation.definition.string.end.haskell'>&quot;</s></s>)])
</span><span class='l l-58 source haskell'>
</span><span class='l l-59 source haskell'>  poolSettings &lt;- <s class='entity name function builtin prelude haskell' data-entity-scope='entity.name.function.builtin.prelude.haskell'>maybe</s> (<s class='entity name function builtin prelude haskell' data-entity-scope='entity.name.function.builtin.prelude.haskell'>fail</s> <s class='string quoted double haskell' data-entity-scope='string.quoted.double.haskell'><s class='punctuation definition string begin haskell' data-entity-scope='punctuation.definition.string.begin.haskell'>&quot;</s>Improper session settings<s class='punctuation definition string end haskell' data-entity-scope='punctuation.definition.string.end.haskell'>&quot;</s></s>) <s class='entity name function builtin prelude haskell' data-entity-scope='entity.name.function.builtin.prelude.haskell'>return</s> $
</span><span class='l l-60 source haskell'>                <s class='constant other haskell' data-entity-scope='constant.other.haskell'>H</s>.poolSettings (<s class='entity name function builtin prelude haskell' data-entity-scope='entity.name.function.builtin.prelude.haskell'>fromIntegral</s> $ configPool conf) 30
</span><span class='l l-61 source haskell'><s class='meta function type-declaration haskell' data-entity-scope='meta.function.type-declaration.haskell'>  <s class='entity name function haskell' data-entity-scope='entity.name.function.haskell'>pool</s> <s class='punctuation separator double-colon haskell' data-entity-scope='punctuation.separator.double-colon.haskell'>::</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>H</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Pool</s> <s class='constant other haskell' data-entity-scope='constant.other.haskell'>P</s>.<s class='constant other haskell' data-entity-scope='constant.other.haskell'>Postgres</s>
</s></span><span class='l l-62 source haskell'>          &lt;- <s class='constant other haskell' data-entity-scope='constant.other.haskell'>H</s>.acquirePool pgSettings poolSettings
</span><span class='l l-63 source haskell'>
</span><span class='l l-64 source haskell'>  runSettings appSettings $ middle $ \req respond -&gt; <s class='keyword control haskell' data-entity-scope='keyword.control.haskell'>do</s>
</span><span class='l l-65 source haskell'>    body &lt;- strictRequestBody req
</span><span class='l l-66 source haskell'>    resOrError &lt;- liftIO $ <s class='constant other haskell' data-entity-scope='constant.other.haskell'>H</s>.session pool $ <s class='constant other haskell' data-entity-scope='constant.other.haskell'>H</s>.tx <s class='constant other haskell' data-entity-scope='constant.other.haskell'>Nothing</s> $
</span><span class='l l-67 source haskell'>      authenticated conf (app conf body) req
</span><span class='l l-68 source haskell'>    either (respond . errResponse) respond resOrError
</span><span class='l l-69 source haskell'>
</span><span class='l l-70 source haskell'>  <s class='keyword other haskell' data-entity-scope='keyword.other.haskell'>where</s>
</span><span class='l l-71 source haskell'>    prettyVersion <s class='punctuation separator equal-sign haskell' data-entity-scope='punctuation.separator.equal-sign.haskell'>=</s> intercalate <s class='string quoted double haskell' data-entity-scope='string.quoted.double.haskell'><s class='punctuation definition string begin haskell' data-entity-scope='punctuation.definition.string.begin.haskell'>&quot;</s>.<s class='punctuation definition string end haskell' data-entity-scope='punctuation.definition.string.end.haskell'>&quot;</s></s> $ <s class='entity name function builtin prelude haskell' data-entity-scope='entity.name.function.builtin.prelude.haskell'>map</s> <s class='entity name function builtin prelude haskell' data-entity-scope='entity.name.function.builtin.prelude.haskell'>show</s> $ versionBranch version</span>
